
@include('Admin.public.head')
<style type="text/css">
    #my-popup2 {
        max-height: 490px;}
    #my-popup {max-height: 600px;}
</style>
<body>
@include('Admin.public.menu')
<div class=" admin-content" id="app">
    {{ csrf_field() }}
    <div class="daohang">
    </div>
	
	<div class="am-popup am-popup-inner" id="my-popup2">
	    <div class="am-popup-hd">
	        <h4 class="am-popup-title">手动分红</h4>
	        <span data-am-modal-close
	              class="am-close">&times;</span>
	    </div>
	    <div class="am-popup-bd">
	        <form class="am-form">
				<div class="am-form-group am-cf" >
				    <label class="sr-only" for="district1" >分红类型：</label>
				    <div class="you">
						<label class="am-checkbox-inline">
						    <input type="radio" value="3" v-model="enctype" data-am-ucheck=""  v-on:click="upperCase1()"
						           class="am-ucheck-radio">
						    <span class="am-ucheck-icons"><i class="am-icon-unchecked"></i><i
						                class="am-icon-checked"></i></span>全部
						</label>
						 <label class="am-checkbox-inline">
						     <input type="radio" value="2" v-model="enctype" data-am-ucheck=""  v-on:click="upperCase1()"
						            class="am-ucheck-radio">
						     <span class="am-ucheck-icons"><i class="am-icon-unchecked"></i><i
						                 class="am-icon-checked"></i></span>服务组
						 </label>
						 <label class="am-checkbox-inline">
						     <input type="radio" value="1" v-model="enctype" data-am-ucheck=""  v-on:click="upperCase1()"
						            class="am-ucheck-radio">
						     <span class="am-ucheck-icons"><i class="am-icon-unchecked"></i><i
						                 class="am-icon-checked"></i></span>合伙人
						 </label>
						 
				    </div>
				</div>
	            <div class="am-form-group am-cf">
	                <label class="sr-only" for="district1" >分红金额1(/人)</label>
	                <div class="you">
	                    <input type="number"  v-on:blur="upperCase1()" class="am-form-field"  v-model="address.money" placeholder="请输入金额">
	                </div>
	            </div>
				<span class="am-form-group am-cf" style="font-weight: bold;">总分红人数：</span><span style="color: red;">@{{ user_name }}</span>
				<div class="am-form-group am-cf" >
				    <label class="sr-only" for="district1" >总分红金额</label>
				    <div class="you">
						 <input class="am-form-field"  v-model="user_name1" disabled="disabled" placeholder="">
				    </div>
				</div>
				<div class="am-form-group am-cf">
				    <label class="sr-only" for="district1" >分红名称</label>
				    <div class="you">
				        <input  class="am-form-field"  v-model="address.name" placeholder="请输入名称">
				    </div>
				</div>
				<div class="am-form-group am-cf" style="display: none;">
				    <label class="sr-only" for="district1" >id</label>
				    <div class="you">
				        <input  class="am-form-field"  v-model="address.a_id" placeholder="请输入名称">
				    </div>
				</div>
	
	            <div class="am-text-center" style="margin-top: 20px ">
	                <a type="button" v-on:click="doApply3()" class="am-btn am-btn-primary">提交</a>
	            </div>
	        </form>
	    </div>
	</div>
    <!--添加模态框-->
    <div class="am-popup am-popup-inner" id="my-popup">
        <div class="am-popup-hd">
            <h4 class="am-popup-title">添加代理</h4>
            <span data-am-modal-close
                  class="am-close">&times;</span>
        </div>
        <div class="am-popup-bd">
            <form class="am-form">
                <div class="am-form-group am-cf">
                    <label class="sr-only" for="district1" >电话</label>
                    <div class="you">
                        <input type="number" class="am-form-field" maxlength="11" v-model="address.phone" placeholder="请输入电话">
                    </div>
                </div>
                <div class="am-radio up-radio-item">
                   <!-- <label>
                        <input type="radio" name="doc-radio-1" value="0" v-model="address.type" checked>
                        省代理
                    </label> -->
                </div>
                <div class="am-radio up-radio-item up-radio-item2">
                    <label>
                        <input type="radio" name="doc-radio-1" value="1" v-model="address.type">
                        市代理
                    </label>
                </div>
                <div class="am-radio up-radio-item up-radio-item3">
                    <label>
                        <input type="radio" name="doc-radio-1" value="2" v-model="address.type">
                        县代理
                    </label>
                </div>

                <div class="gray-panel">
                    <div class="paoduct-title-panel">
                        {{--<h2 class="checkout-h2"><span class="am-badge am-round am-badge-warning ">2</span> 申请城市</h2>--}}
                        <p>
                        <div data-toggle="distpicker">
                            <label class="sr-only" for="province1">Province</label>
                            <select id="province1" v-model="address.province" required>
                            </select>
                            <div class="form-group">
                                <label for="city1">City</label>
                                <select class="form-control" id="city1" v-model="address.city" required>
                                </select>
                            </div>
                            <div class="form-group">
                                <label class="sr-only" for="district1" >District</label>
                                <select class="form-control" id="district1" v-model="address.district">
                                </select>
                            </div>
                        </div>
                        @{{address.districts}}
                        </p>
                    </div>
                </div>
                <div class="am-text-center" style="margin-top: 20px ">
                    <a type="button" v-on:click="doDistrict()" class="am-btn am-btn-success">添加区</a>
                    <a type="button" v-on:click="doApply()" class="am-btn am-btn-primary">申请</a>
                </div>
            </form>
        </div>
    </div>
	
	
	<div class="am-popup am-popup-inner" id="my-popup1">
	    <div class="am-popup-hd">
	        <h4 class="am-popup-title">合伙人</h4>
	        <span data-am-modal-close
	              class="am-close">&times;</span>
	    </div>
	    <div class="am-popup-bd">
	        <form class="am-form">
	            <div class="am-form-group am-cf">
	                <label class="sr-only" for="district1" >合伙人名单</label>
	                <div class="you">
	                    <!-- <input  class="am-form-field"  v-model="address.partner"> -->
						<textarea style="height: 200px;" class="am-form-field"  v-model="address.partner"></textarea>
	                </div>
	            </div>
	            <div class="am-text-center" style="margin-top: 20px ">
	                <a type="button" v-on:click="doApply1()" class="am-btn am-btn-primary">添加</a>
	            </div>
	        </form>
	    </div>
	</div>
	
	
	
    <div class="admin-biaogelist">
        <div class="listbiaoti am-cf">
            <ul class="am-icon-users"> 代理商管理</ul>
            <dl>
                <button type="button" data-am-modal="{target: '#my-popup'}" class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus" >
                    添加代理
                </button>
            </dl>
            <dl class="am-icon-home" style="float: right;">当前位置： 首页 > <a href="#">代理商列表</a></dl>
            <!--这里打开的是新页面-->
        </div>
        <div class="am-btn-toolbars am-btn-toolbar am-kg am-cf">
            <ul>
                <li>
                    <template>
                        <el-select v-model="keyword.type" placeholder="代理类型">
                            <el-option
                                    size="medium"
                                    v-for="item in options"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </template>
                </li>
                {{--<li>--}}
                    {{--<div class="block">--}}
                        {{--<el-date-picker--}}
                                {{--v-model="keyword.created_at"--}}
                                {{--type="daterange"--}}
                                {{--value-format="yyyy-MM-dd"--}}
                                {{--range-separator="~"--}}
                                {{--start-placeholder="开始日期"--}}
                                {{--end-placeholder="结束日期">--}}
                        {{--</el-date-picker>--}}
                    {{--</div>--}}
                {{--</li>--}}

                <li>
                    <template>
                        <el-select v-model="keyword.status" placeholder="代理状态">
                            <el-option
                                    size="medium"
                                    v-for="item in ordertype"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </template>
                </li>

                <li>
                    <el-input v-model="keyword.keyword" class="keywords" placeholder="关键词搜索"></el-input>
                </li>
                <li>
                    <el-button type="primary" v-on:click="changeClick()">搜索</el-button>
                </li>
                <li> <el-button type="danger" v-on:click="resetOrder()">重置</el-button></li>
				<li> <el-button type="success" v-on:click="sendDataTo('test')" data-am-modal="{target: '#my-popup2'}">分红</el-button></li>
            </ul>
        </div>


        <form class="am-form am-g">
            <table width="100%" id="test" class="am-table am-table-bordered am-table-radius am-table-striped">
                <thead>
                <tr class="am-success">
					 <th>
					                        <input type="checkbox" id="selectAll" value=null />
					                    </th>
                    <th class="table-id">ID</th>
                    <th class="table-title">账号</th>
                    <th class="table-title">姓名</th>
                    <th class="table-type">代理类型</th>
                    <th class="table-author am-hide-sm-only">省</th>
                    <th class="table-author am-hide-sm-only">市</th>
                    <th class="table-date am-hide-sm-only">县区</th>
					
                    
                    <th class="table-date am-hide-sm-only">收入总额</th>
                    <th class="table-date am-hide-sm-only">实际收入总额</th>
                    <th class="table-date am-hide-sm-only">添加时间</th>
                    <th class="table-date am-hide-sm-only">审核人</th>
					<th class="table-date am-hide-sm-only">状态</th>
                    <th class="table-date am-hide-sm-only">修改时间</th>
                    <th width="130px" class="table-set">操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="val,index in ApplyList">
					<td v-if="val.status == 1">
					                        <input :value="val.id" type="checkbox" name="check" />
					                    </td>
					<td v-show="val.status == 0 || val.status == 2 || val.status == 3"> </td>
                    <td>@{{ val.id }}</td>
                    <td>@{{ val.user }}</td>
                    <td>@{{ val.name }}</td>
                    <!-- <td v-show="val.type == 0">省代理</td> -->
                    <td v-show="val.type == 1">市代理 </td>
                    <td v-show="val.type == 2">县代理 </td>
                    <td class="am-hide-sm-only">
                        @{{ val.province }}
                    </td>
                    <td class="am-hide-sm-only">@{{ val.city }}</td>
                    <td class="am-hide-sm-only">@{{ val.district }}</td>
                    
                    <td>@{{ val.allMoney }}</td>
                    <td>@{{ val.bonus }}</td>
                    <td>@{{ val.created_at }}</td>
                    <td>@{{ val.verifier }}</td>
					<td v-show="val.status == 0" >待审核</td>
					<td v-show="val.status == 1" style="color: green;">已通过</td>
					<td v-show="val.status == 2" style="color: red;">已拒绝</td>
					<td v-show="val.status == 3" style="color: red;">已回收</td>
                    <td>@{{ val.updated_at }}</td>
                    {{--<td>--}}
                        {{--<span v-on:click="editType(val.uid,index)" v-show="val.type == 1" title="正常登陆" style="cursor: pointer;"><i class="am-icon-check"></i></span>--}}
                        {{--<span v-on:click="editType(val.uid)" v-show="val.type == 0" title="已禁用" style="cursor: pointer;"><i class="am-icon-close"></i></span>--}}
                    {{--</td>--}}
                    <td style="width:250px;">
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">

                                <a class="am-btn am-btn-success am-radius" v-show="val.status == 0"  v-on:click="approve(val.id)" title="审核通过">通过</a>
                                <a class="am-btn am-btn-secondary" v-show="val.status == 0"  v-on:click="reject(val.id)" title="拒绝通过">拒绝</a>
                                <a class="am-btn am-btn-warning" v-show="val.status == 1"  v-on:click="approve(val.id)"  title="回收">回收</a>
                                <a class="am-btn am-btn-danger am-radius" v-show="val.status == 2"  title="拒绝" >已拒绝</a>
                                <a class="am-btn am-btn-danger am-radius" v-show="val.status == 3"  title="拒绝" >已回收</a>
                                <a class="am-btn am-btn-danger am-radius" v-show="val.status == 3"  title="开通"  v-on:click="back(val.id)" >开通</a>
                                <a class="am-btn am-btn-danger am-radius" v-show="val.status == 1" data-am-modal="{target: '#my-popup'}" v-on:click="doEditor(val)" title="拒绝" >编辑</a>
								<a style="background-color: #4db14d;border-color: #4db14d;" class="am-btn am-btn-danger am-radius" v-show="val.status == 1"  v-on:click="par(val.id)"  >合伙人</a>
                            </div>
                        </div>
						
                    </td>
                </tr>
                </tbody>
            </table>
            <!--分页-->
            <ul class="am-pagination am-fr">
                <div class="block">
                    <el-pagination
                            background
                            :page-size="PagesData.per_page"
                            :current-page = "PagesData.current_page"
                            layout="total , prev, pager, next"
                            :total="PagesData.total"
                            @prev-click="changeClick"
                            @next-click="changeClick"
                            @current-change="changeClick">
                    </el-pagination>
                </div>
            </ul>

        </form>
        <script src="{{ URL::asset('js/address/distpicker.data.js') }}"></script>
        <script src="{{ URL::asset('js/address/distpicker.js') }}"></script>
        <script>
            var app = new Vue({
                el:"#app",
                data: {
					user_name:'',
                    ApplyList : [], //代理商列表
                    PagesData:[],//分页
                    options: [
						/* {
                        value: '0',
                        label: '省代理'
                    }, */
					{
                        value: '1',
                        label: '市代理'
                    },{
                        value: '2',
                        label: '县代理'
                    }],
                    ordertype: [{
                        value: '0',
                        label: '待审核'
                    }, {
                        value: '1',
                        label: '通过'
                    },{
                        value: '2',
                        label: '拒绝'
                    },{
                        value: '3',
                        label: '回收'
                    }],
                    keyword:{ //关键字搜索
                        type:'',
                        status:'',
                        keyword:'',
                        // created_at:'',
                    },
					enctype:3,
					user_name1:"",
                    address: {
                        'id':'',
                        'phone':'',
                        'type':'',
                    	//'enctype':3,
                        'province':'北京市',
                        'city':'',
                        'district':'',
                        'districts':'',
                        'status':'',
                    	'partner':'',
                    	//'user_name':'',
                    	'name':'',
                    	'a_id':[]
                    },
                },
                //事件
                methods: {
					par:function (id) {
						window.location.href="/admin/members/agentList?id="+id;
					},
                    //选择当前页
                    changeClick:function(e){
                        var rico = this
                        $.get("/admin/members/doApply",{'_token':'{{csrf_token()}}',class:'select',page:e,keyword:app.keyword},function (res) {
                            if(res.code){
                                app.ApplyList = res.data.data
                                app.PagesData = res.data
                            } else {
                                layer.msg(res.data);
                            }
                        });
                    },

                    initialize:function () {
                        var rico = this
                        //代理商列表
                        $.get("/admin/members/doApply",{'_token':'{{csrf_token()}}',class:'select'},function (res) {
                            if(res.code){
                                app.ApplyList = res.data.data
                                app.PagesData = res.data
                            } else {
                                layer.msg(res.data);
                            }
                        });

                    },
                    //添加区县
                    doDistrict:function () {
                        app.address.districts = (app.address.districts == '')?app.address.district:app.address.districts+','+app.address.district
                    },
					findsMember:function (id) {
						var id1 =[id];
					    $.post("/admin/system/shareholders",{'_token':'{{csrf_token()}}',class:'details',a_id:id1},function (res) {
					        if(res.code){
								app.address.a_id = id;
					        } else {
					            app.address.a_id = id;
					        }
					    });
					},
					doApply3:function(){
						var rico = this
						//代理商列表
						var id3 = [app.address.a_id]
					    $.post("/admin/system/shareholders", {'_token': '{{csrf_token()}}','class':'submit',a_id:id3,enctype:app.enctype,name:app.address.name,money:app.address.money,number:app.user_name,total_money:app.user_name1}, function (res) {
					        if (res.code) {
								layer.msg(res.data);
					            window.location.href="/admin/members/apply";
					        } else {
					            layer.msg(res.data);
					        }
					    });
					},
					sendDataTo:function(id){
						 var inputs = document.getElementById(id).getElementsByTagName("input");
						             var allData = new Array();
						             var num = 0;
						                      for(var i = 0; i < inputs.length; i++){
						                          // 判断该input中是否为checkbox
						                          if(inputs[i].type == "checkbox" ){
						                              //判断该checkbox是否被选中，如果被选中获取table行中的指定元素
						                              if(inputs[i].checked){
						                                  var checkRow = inputs[i].value;
						                                  //tr对应table的行
						                                  //var tr = checkRow.parentNode.parentNode;
						                                  //tds对应每一行中的对应的每一列
						                                  //var tds = tr.cells;
						          　　　　　　　　　　　　　　// 组织要发送的数据
						                                  //var temp = new Array();
														   //console.log(checkRow)
						                                  //temp[0] = checkRow;
						                                  allData[num] = checkRow;
														  
						                                  num++;
						                              }
						                          }
						                      };
							console.log(allData)
							$.get("/admin/system/shareholders",{'_token':'{{csrf_token()}}',class:'details',a_id:allData},function (res) {
							    app.address.a_id = allData;
							});
					},
                    //代理申请
                    doApply:function(){
                        var rico = this
                        if(!(/^[1][3,4,5,7,8,9][0-9]{9}$/.test(app.address.phone))){
                            layer.msg('请输入正确的电话号码');
                            return false;
                        }
                        $.post("/admin/members/doApply", {'_token': '{{csrf_token()}}','class':'apply',address:app.address}, function (res) {
                            if (res.code) {
                                layer.msg(res.data);
                                app.address.districts = '';
                                rico.initialize();
                            } else {
                                layer.msg(res.data);
                            }
                        });
                    },
					doApply1:function(){
					    $.post("/admin/members/doApply", {'_token': '{{csrf_token()}}',class:'partner',partner:app.address.partner,id:app.address.id}, function (res) {
					        if (res.code) {
					            layer.msg(res.data);
								location.href='/admin/members/apply'
					        } else {
					            layer.msg(res.data);
					        }
					    });
					},
					upperCase1:function () {
						var id2 = [app.address.a_id]
					    $.post("/admin/system/shareholders", {'_token': '{{csrf_token()}}',class:'details',enctype:app.enctype,a_id:app.address.a_id,money:app.address.money}, function (res) {
					        if (res.code == 1 ) {
								app.user_name = res.count
								app.user_name1 = res.total
					        } else {
					            layer.msg(res.data);
					        }
					    });
					},
                    //编辑代理
                    doEditor:function(data){
                        app.address.id = data.id;
						app.address.partner = data.partner;
                        app.address.type = data.type;
                        app.address.phone = data.phone;
                    },
					AllCheck:function(thisform){
						var selectState = false;
					     for (var i = 0; i < thisform.elements.length; i++){
					                // 提取控件  
					                var checkbox = thisform.elements[i];
					                // 修改每个checkbox的状态
					                checkbox.checked = !selectState;
					            }
					            selectState = !selectState;
					},
                    //审核通过
                    approve:function (id) {
                        var that = this;
                        $.get("/admin/members/doApply",{'_token':'{{csrf_token()}}',class:'edit',id:id},function (res) {
                            if(res.code){
                                layer.msg(res.data,{icon: 6},function () {
                                    // location.reload();
                                    that.initialize();
                                },500);
                            }
                        });
                    },
                    //拒绝
                    reject:function(id) {
                        var that = this;
                        $.get("/admin/members/doApply",{'_token':'{{csrf_token()}}',class:'reEdit',id:id},function (res) {
                            if(res.code){
                                layer.msg(res.data,{icon: 6},function () {
                                    // location.reload();
                                    that.initialize();
                                },500);
                            }
                        });
                    },
                    //开通
                    back:function(id) {
                        var that = this;
                        $.get("/admin/members/doApply",{'_token':'{{csrf_token()}}',class:'back',id:id},function (res) {
                            if(res.code){
                                layer.msg(res.data,{icon: 6},function () {
                                    // location.reload();
                                    that.initialize();
                                },500);
                            }
                        });
                    },

                    //重置
                    resetOrder:function(){

                        location.reload();
                    }
                },

                //自动执行
                mounted: function () {
                    this.initialize();//分公司
                },
            })
			
			$(function(){
			            var selectAll=$("#selectAll")
			            selectAll.click(function(){
			                if (selectAll.prop("checked") == true) {
			                    // 上面的复选框已被选中
			                    $(":checkbox[name='check']").prop("checked", true);
			                } else {
			                    // 上面的复选框没被选中
			                    $(":checkbox[name='check']").prop("checked", false);
			                }
			            })
			            $("#tbodyss :input").click(function(){
			                //获取复选框的个数
			                var length1=$("#tbodyss :input").length
			                //获取选中的复选框的个数
			                var length2=$("#tbodyss :checked").length
			                if(length1 == length2){
			                    $("#selectAll").prop("checked",true);
			                }else{
			                    $("#selectAll").prop("checked",false);
			                }
			            })
			            
			        })
        </script>
@include('Admin.public.foot')